<!DOCTYPE html>
<html lang="en">
<head>
          <meta charset="UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Document</title>
</head>
<body>
    <h1>收银台小程序4.0</h1>
    商品单价<input type="text" id="price"><br>
    商品单价<input type="text" id="number"><br>
    <button onclick="cal()">计算应付金额</button><br>
    应付金额<input type="text" id="pay"><br>
</body>
<script>
    function cal(){
        //得到单价
        let price = document.getElementById("price").value;
        //得到数量
        let number = document.getElementById("number").value;
        //计算金额
        let pay = parseInt(price) +parseInt(number);
        //计算的结果返回到页面文本
        document.getElementById("pay").value = pay;
    }
</script>
</html>